/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.ui.controls;

import ac.lib.users.permissions;
import ac.settings.dataModelurls;
import static ac.settings.dataModelurls.URL_Image;
import ac.ui.utils;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import ac.lib.users.permissions;

/**
 *
 * @author empcl_000
 */
public class PCLTabs extends JTabbedPane implements dataModelurls {

    ImageIcon closeXIcon;
    private Dimension closeButtonSize;

    public void openPanel(final PCLPanel content, String title) {

        permissions p = new permissions();
        if (content.getType() == null || p.isView(content.getType(), true)) {

            openp(content, title);

        }
    }

    void openp(final PCLPanel content, String title) {
        closeXIcon = new ImageIcon(getClass().getResource(URL_Image + "close.png"));
        closeButtonSize = new Dimension(closeXIcon.getIconWidth() + 2, closeXIcon.getIconHeight() + 2);
        JPanel tab = new JPanel();
        tab.setOpaque(false);

        JLabel tabLabel = new JLabel(title);

        JButton tabCloseButton = new JButton(closeXIcon);
        tabCloseButton.setPreferredSize(closeButtonSize);
        tabCloseButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                int closeTabNumber = indexOfComponent(content);
                removeTabAt(closeTabNumber);
            }

        });

        tab.add(tabLabel, BorderLayout.WEST);
        tab.add(tabCloseButton, BorderLayout.EAST);

        // JScrollPane scroller = new JScrollPane(content);
        addTab(null, content);

        setTabComponentAt(getTabCount() - 1, tab);

    }

}
